﻿using System.Diagnostics;

namespace MyFifthCSharp1
{/// <summary>
/// 随机给出提示，要求用户按键，重复N次，要求统计总用时及出错次数
/// </summary>
    internal class Program
    {   //枚举,注意顶级语句必须位于命名空间和类型声明之前
        enum Direction
        {
            Up,
            Down,
            Left,
            Right
        }
        const int NumberOfTest = 10;
        static void Main(string[] args)
        {
            int NumberOfError = 0;
            Random random = new Random();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < NumberOfTest; i++)
            {
                //下面的random出来的是数字
                //string word=Convert.ToString(random.Next(0,4));
                //在枚举内出现，原本的样子
                Direction direction = (Direction)random.Next(0, 4);
                Console.WriteLine(direction);
                //读取的东西打出来是一个复杂的东西，但把input.Key使用了，就变成了UpArrow,小d变D
                var input = Console.ReadKey();


                //用一个键去表示，一个单词。
                switch (direction)
                {
                    case Direction.Up:
                        //ConsoleKey本身就是一种枚举，键盘上的键被枚举了
                        
                        if (input.Key == ConsoleKey.UpArrow)
                            Console.WriteLine("输入正确");
                        else NumberOfError++;
                        break;

                    case Direction.Down:
                        if (input.Key == ConsoleKey.DownArrow)
                            Console.WriteLine("输入正确");
                        else NumberOfError++;
                        break;
                    case Direction.Left:
                        if (input.Key == ConsoleKey.LeftArrow)
                            Console.WriteLine("输入正确");
                        else NumberOfError++;
                        break;
                    case Direction.Right:
                        if (input.Key == ConsoleKey.RightArrow)
                            Console.WriteLine("输入正确");
                        else NumberOfError++;
                        break;
                }
            }
            sw.Stop();
            TimeSpan timespan = sw.Elapsed;
            Console.WriteLine("程序耗时:'{0}'秒", timespan);
            Console.WriteLine($"错误次数{NumberOfError}");




        }
    }
}
